package xuexi;


class Array{
    private int []data;
    private int foot;//数据下标索引
    public Array(int len){
        if (len>0){
            this.data=new int[len]; //开辟数组
        }else{
            this.data=new int[1];   //开辟一个空间
        }
    }
    //实现数组容量扩充
    public void inrement(int num){
        int []newData=new int[this.data.length+num];
        System.arraycopy(this.data,0,newData,0,this.data.length);
        this.data=newData;//改变数组引用
    }
    public boolean add(int num){//数据增加
        if (this.foot<this.data.length){
            this.data[this.foot ++]=num;
            return true;
        }
        return false;
    }
    public int [] getData(){
        return this.data;
    }
}

class sortArray extends Array{//定义排序子类

    public sortArray(int len) {
        super(len);
    }
    @Override
    public int[] getData(){
        java.util.Arrays.sort(super.getData());
        return super.getData();
    }
}
class revereArray extends Array{//定义反转子类

    public revereArray(int len) {
        super(len);
    }
    @Override
    public int[] getData(){
        int center=super.getData().length/2;
        int head=0;
        int tial=super.getData().length-1;
        for (int x=0;x<center;x++){
            int temp=super.getData()[head];
            super.getData()[head]=super.getData()[tial];
            super.getData()[tial]=temp;
            head++;
            tial--;
        }
        return super.getData();
    }
}
public class shuzu {
    public  static void main(String[] args){
        revereArray array=new revereArray(5);
        System.out.println(array.add(10));
        System.out.println(array.add(2));
        System.out.println(array.add(1));
        System.out.println(array.add(31));
        System.out.println(array.add(11));
        array.inrement(2);
        System.out.println(array.add(5));
        System.out.println(array.add(52));
        int[] retult=array.getData();
        for (int temp:retult){
            System.out.print(temp+"--");
        }

    }
}
